What is @stdlib/assert-is-plain-object?
@stdlib/assert-is-plain-object is a utility package that provides a function to check if a value is a plain object. A plain object is an object created by the Object constructor or with an object literal.
What are @stdlib/assert-is-plain-object's main functionalities?
Check if a value is a plain object
This feature allows you to check if a given value is a plain object. In the code sample, the function `isPlainObject` is used to check if `obj` is a plain object, which returns `true`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const obj = { 'a': 1, 'b': 2 };
const result = isPlainObject(obj);
console.log(result); // true
Check if a non-object value is a plain object
This feature allows you to check if a non-object value is a plain object. In the code sample, the function `isPlainObject` is used to check if `notAnObject` is a plain object, which returns `false`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const notAnObject = 42;
const result = isPlainObject(notAnObject);
console.log(result); // false
Check if an array is a plain object
This feature allows you to check if an array is a plain object. In the code sample, the function `isPlainObject` is used to check if `arr` is a plain object, which returns `false`.
const isPlainObject = require('@stdlib/assert-is-plain-object');
const arr = [1, 2, 3];
const result = isPlainObject(arr);
console.log(result); // false
Other packages similar to @stdlib/assert-is-plain-object
lodash.isplainobject
The `lodash.isplainobject` package is a utility from the Lodash library that checks if a value is a plain object. It is similar to `@stdlib/assert-is-plain-object` in functionality but is part of the larger Lodash utility library, which provides a wide range of utility functions for JavaScript.
is-plain-object
The `is-plain-object` package is a standalone utility that checks if a value is a plain object. It is similar to `@stdlib/assert-is-plain-object` in that it focuses solely on determining if a value is a plain object, but it is a smaller, more focused package.
isobject
The `isobject` package is a utility that checks if a value is an object and not an array or null. While it is broader in scope than `@stdlib/assert-is-plain-object`, it can be used to achieve similar functionality by further checking if the object is a plain object.
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
isPlainObject
Test if a value is a plain object.
Installation
npm install @stdlib/assert-is-plain-object
Usage
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
isPlainObject( value )
Tests if a value
is a plain object
.
var bool = isPlainObject( {} );
bool = isPlainObject( null );
Examples
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
var bool = isPlainObject( {} );
bool = isPlainObject( Object.create( null ) );
bool = isPlainObject( [] );
bool = isPlainObject( null );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
License
See LICENSE.
Copyright
Copyright © 2016-2023. The Stdlib Authors.
0.1.1 (2023-10-03)
No changes reported for this release.
</section>
<!-- /.release -->
<section class="release" id="v0.1.0">